﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessLibary;
using DevExpress.Utils;

namespace Medicare
{
    public partial class FrmItemRelationZL : Form
    {
        public FrmItemRelationZL()
        {
            InitializeComponent();
        }
        private DataView dv1;
        private DataView dv2;
        private DataSet dataSet1=new DataSet();
        private DataSet dataSet2=new DataSet();
        MIItemRelationZLFacade miItemRelationZLFacade;
        private WaitDialogForm wdialog; //等侍窗体定义

        private void btnCorrespond_Click(object sender, EventArgs e)
        {
            string itemid;

            itemid = gridView2.GetDataRow(gridView2.FocusedRowHandle)["XMBM"].ToString();

            this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle)["itemidmed"] = itemid;
        }

        private void FrmItemRelationYP_Load(object sender, EventArgs e)
        {
            dv1 = new DataView();
            dv2 = new DataView();

            miItemRelationZLFacade = new MIItemRelationZLFacade();

            wdialog = new WaitDialogForm("正在更新医院检治目录...");
            miItemRelationZLFacade.ImportNewData();
            wdialog.Close();

            wdialog = new WaitDialogForm("正在装载医院检治目录...");
            dataSet1 = miItemRelationZLFacade.FindAll();
            wdialog.Close();

            wdialog = new WaitDialogForm("正在装载医保检治目录...");

            YBZLInfoFacade ybExamineInfoFacade = new YBZLInfoFacade();

            this.dataSet2 = ybExamineInfoFacade.FindAll();
            wdialog.Close();

            dv1 = dataSet1.Tables[0].DefaultView;
            dv2 = dataSet2.Tables[0].DefaultView;
            this.gridControl1.DataSource = dv1;
            this.gridControl2.DataSource = dv2;
            this.gridView1.GroupPanelText = "医院检治目录  " + this.gridView1.RowCount;
            this.gridView2.GroupPanelText = "医保检治目录  " + this.gridView2.RowCount;
            this.Text = "检治对应关系维护";

 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            gridView1.UpdateCurrentRow();
            miItemRelationZLFacade.updateEntity(this.dataSet1);
            System.Windows.Forms.MessageBox.Show("保存成功!");
        }

        private void textEdit2_EditValueChanged(object sender, EventArgs e)
        {
            string FilterStr = "";

            FilterStr = FilterStr + " XMBM like '" + this.textEdit2.Text.ToLower() + "%' OR XMBM like '" + this.textEdit2.Text.ToUpper() + "%'";
            FilterStr = FilterStr + " OR PYZJM like '" + this.textEdit2.Text.ToLower() + "%' OR PYZJM like '" + this.textEdit2.Text.ToUpper() + "%'";

            dv2.RowFilter = FilterStr;
        }

        private void textEdit1_EditValueChanged(object sender, EventArgs e)
        {
            //his filter
            string FilterStr = "";
            FilterStr = FilterStr + " ITEMIDHIS like '" + textEdit1.Text.ToLower() + "%' OR ITEMIDHIS like '" + textEdit1.Text.ToUpper() + "%'";
            FilterStr = FilterStr + " OR py like '" + textEdit1.Text.ToLower() + "%' OR py like '" + textEdit1.Text.ToUpper() + "%'";
            this.dv1.RowFilter = FilterStr;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            gridView1.GetDataRow(this.gridView1.FocusedRowHandle)["itemidmed"] = "";
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
